package cn.sxt.oop;

/**
 * 体验值传递(对象是特殊的值传递：共享对象传递)
 */
public class TestSwap {
    private int num;

    public TestSwap(int num) {
        this.num = num;
    }

    @Override
    public String toString() {
        return "Test{" +
                "num=" + num +
                '}';
    }

    public static void main(String[] args) {
        int i = 10;
        int j = 20;
        swap(i, j);
        //10
        System.out.println(i);
        //20
        System.out.println(j);

        TestSwap ii = new TestSwap(i);
        TestSwap jj = new TestSwap(j);
        swapInstance(ii, jj);
        //Test{num=10}
        System.out.println(ii);
        //Test{num=20}
        System.out.println(jj);
    }

    private static void swap(int i, int j) {
        int temp = i;
        i = j;
        j = temp;
    }

    private static void swapInstance(TestSwap i, TestSwap j) {
        TestSwap temp = i;
        i = j;
        j = temp;
    }


}
